package com.wondertek.service.mapper.business;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wondertek.service.dto.business.res.DeviceErrorRecordMessageRes;
import com.wondertek.service.entity.business.DeviceErrorRecordMessagePo;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;


/**
 * @author wangyu
 */
public interface DeviceErrorRecordMessageMapper extends BaseMapper<DeviceErrorRecordMessagePo> {

    /**
     * 根据userId查询告警站内消息
     * @param userId
     * @return
     */
    @Select("<script> select id,type,der_id,error_type,site_id,site_name,error_time,is_read from device_error_record_message derm where is_read = 0 <if test='userId != \"1\" '> and exists (select 1 from user_site us where us.site_id = derm.site_id and us.user_id = #{userId}) </if> order by create_time desc  </script>")
    Page<DeviceErrorRecordMessageRes> findMessageByUserId(@Param("userId") String userId, Page page);
}
